<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <script type="text/javascript" src="../../inc/ctx.jsp"></script>
        <script type="text/javascript" src="../js/g.js"></script>
        <script type="text/javascript" src="../js/shoptype.js"></script>
        <script type="text/javascript" src="../js/channeltype.js"></script>
        <link href="../css/com.css" type="text/css" rel="stylesheet"/>
        <style>
            b.b1{display:block;padding:1px 5px 1px 5px;border:1px solid #E0E0E0;}
        </style>
    </head>
    <body>
        <div id="panel">
            <form id="queryFrm">
                <table border="0" cellspacing="0" cellpadding="0">
                    <tr class="trhd">
                        <td colspan="3"><h3 class="s1">HotShop查询</h3></td>
                        <td width="8%">&nbsp;</td>
                        <td colspan="4">&nbsp;</td>
                    </tr>
                    <tr>
                        <td width="2%" height="34">&nbsp;</td>
                        <td width="7%" class="r">发布状态：</td>
                        <td width="19%">
                            <select id="pubstate" name="pubstate" style="width:100px;">
                                <option value=""></option>
                                <option value="1">1-是-</option>
                                <option value="0">0-否-</option>
                            </select>
                            <span class="r">
                                <input onClick="Shop.updatePubState();" type="button" id="updateBtn1" value="更新">
                            </span></td>
                        <td class="r">发布时间：</td>
                        <td width="27%">
                            从 <input type="text" id="pubBeginTime" name="pubBeginTime" value="" maxlength="19" style="width:100px;" onclick="cdpn('pubBeginTime');"/>
                            到 <input type="text" id="pubEndTime" name="pubEndTime" value="" maxlength="19" style="width:100px;"  onclick="cdpn('pubEndTime');"/>
                        </td>
                        <td width="9%" class="r">是否可评：</td>
                        <td colspan="2"><select id="iscmt" name="iscmt" style="width:100px;">
                                <option value=""></option>
                                <option value="0">0-关闭-</option>
                                <option value="1">1-开放-</option>
                            </select>
                            <input onClick="Shop.updateCmtState();" type="button" id="updateBtn2" value="更新"></td>
                    </tr>
                    <tr>
                        <td height="33">&nbsp;</td>
                        <td class="r">SHOP类型：</td>
                        <td><script>out_shoptype();</script></td>
                        <td class="r">更新时间：</td>
                        <td>从
                            <input type="text" id="updateBeginTime" name="updateBeginTime" value="" maxlength="19" style="width:100px;" onclick="cdpn('updateBeginTime');"/>
                            到
                            <input type="text" id="updateEndTime" name="updateEndTime" value="" maxlength="19" style="width:100px;"  onclick="cdpn('updateEndTime');"/></td>
                        <td class="r">每页显示：</td>
                        <td colspan="2"><select name="listsize" id="listsize">
                                <option value="10">10条</option>
                                <option value="20">20条</option>
                                <option value="50">50条</option>
                            </select></td>
                    </tr>
                    <tr>
                        <td height="33">&nbsp;</td>
                        <td class="r">SHOP ID：</td>
                        <td><input type="text" id="shopid" name="shopid" value=""  style="width:120px;"  onclick="this.value=''"/></td>
                        <td class="r">板块类别：</td>
                        <td><script>out_select('channeltype');</script><span class="r">
                                <input onClick="Shop.updateCatalog();" type="button" id="updateBtn3" value="更新类别">
                            </span></td>
                        <td class="r">SHOP名称：</td>
                        <td colspan="2"><input id="titleKeyword" name="titleKeyword" value="" maxlength="20" style="width:120px;" onClick="this.value=''"/></td>
                    </tr>
                    <tr>
                        <td height="33">&nbsp;</td>
                        <td class="r">查看次数：</td>
                        <td>从 <input type="text" id="beginHitNum" name="beginHitNum" value=""  style="width:50px;"/>到
                            <input type="text" id="endHitNum" name="endHitNum" value=""  style="width:50px;"/></td>
                        <td class="r">信息类别：</td>
                        <td>
                            <input type="hidden" name="cid" id="cid" value=""/>
                            ctp:
                            <input type="text" name="ctp" id="ctp" value="" style="width:50px;" readonly="readonly" onClick="selectCatelogs();"/>
                            <input type="button" value="清空" onClick="$('#cid').val('');$('#ctp').val('');"/></td>
                        <td class="r">&nbsp;</td>
                        <td width="16%">&nbsp;</td>
                        <td width="12%"><input name="rownum" id="rownum" value="" type="hidden" />
                            <input name="crow" id="crow" value="" type="hidden" />
                            <input name="currpage" id="currpage" value="" type="hidden" /></td>
                    </tr>
                    <tr>
                        <td height="33">&nbsp;</td>
                        <td class="r">发布时间：</td>
                        <td><input type="text" id="pubtime" name="pubtime" value="" maxlength="19" style="width:100px;" onClick="cdpn('pubtime');"/>
                            <input onClick="Shop.updatePubTime();" type="button" id="updateBtn6" value="更新"></td>
                        <td class="r">更新时间：</td>
                        <td><input type="text" id="updatetime" name="updatetime" value="" maxlength="19" style="width:100px;" onClick="cdpn('updatetime');"/>
                            <input onClick="Shop.doUpdatetime();" type="button" id="updateBtn7" value="更新"></td>
                        <td class="r"></td>
                        <td colspan="2"><span class="r">
                                <input onClick="Shop.list(1, 0);" type="button" class="button small orange" id="submitBtn" value="Φ 查询">
                                <input onClick="Shop.del();" type="button" class="button small gray" id="delBtn" value="x 删除">
                            </span></td>
                    </tr>
                </table>
            </form>
        </div>


        <div class="databox">
            <table border="0" cellspacing="0" cellpadding="0">
                <tr>
                    <th width="3%">&nbsp;<a href="javascript:ut.swapsel('sel');">反选</a></th>
                    <th width="25%">名称/ID/类别/URL</th>
                    <th width="10%">主图</th>
                    <th width="11%">发布/更新时间</th>
                    <th width="8%">SHOP类型</th>
                    <th width="6%">得分</th>
                    <th width="10%">地区</th>
                    <th width="6%">是否发布</th>
                    <th width="6%">是否可评</th>
                    <th width="5%">查看次数</th>
                    <th width="10%">操作</th>
                </tr>
                <tbody class="tbchg" id="datalist"></tbody>
            </table>
        </div>
        <div class="page" id="page"></div>

        <div style="display:block;clear:both;width:98%;height:50px;">&nbsp;</div>





        <!-- 数据处理 -->
        <script id="listTpl" type="text/html">
            {%  for(var k in list){ var e = list[k]; %}
        <tr>
            <td><input name="sel" type="checkbox" value="{%=e.shopid%}"/></td>
            <td>
                <span style="font-size:13px;cursor:pointer;" onclick="Shop.view('{%=e.shopid%}')">{%=e.shopname%}</span><br/>
                <span class="s1">id: {%=e.shopid%} , ctp:{%=e.ctp%}</span><br/>
                <b><a href="{%=e.url%}" target="_blank">{%=e.url%}</a></b>
            </td>
            <td><span class="img1">
                    <img src="{%=getResizeImgUrl(e.pic,'ss')%}" height="40" />
                </span>
            </td>
            <td>{%=parseDate(e.pubtime,16)%} / {%=highlightOverTime(e.updatetime)%} </td>
            <td>{%=getShopType(e.shoptype)%} </td>
            <td>{%=fmtNumber(e.scorerate,'#.00')%} </td>
            <td>{%=e.local%} </td>
            <td>{%=getPubState(e.pubstate)%} </td>
            <td>{%=getCmtState(e.iscmt)%} </td>
            <td>{%=e.hitnum%} </td>
            <td><a href="javascript:;" onclick="Shop.edit('{%=e.shopid%}');">编辑</a></td>
        </tr>
        {%}%}
    </script>

    <script type="text/javascript">
        var $lsout = $('#datalist');
        var $ls = $('#listsize');
        var $rownum = $('#rownum');
        var $crow=$('#crow');
        var $curpage=$('#currpage');
        var Shop={
            list:function(pgno,r){
                var ls = parseInt($ls.val());
                var step =10;
                var cr = (ls * ( pgno - 1 ));
                $rownum.val(r);
                $crow.val(cr);
                $curpage.val(pgno);
                var params = ut.getFormData('#queryFrm');
                params._t=ut.r();
                $.get('../app/hotshop/list_factor.shtm',params,function(d){
                    var x = d;
                    rn=x.rownum;
                    $rownum.val(rn);
                    if(rn>0){
                        ut.outpage(pgno, rn, 'Shop.list','page', ls, step);
                        $lsout.html(template.render('listTpl',x));
                    }else{
                        $lsout.html('<tr><td colspan="8">暂无数据.</td></tr>');
                        $('#page').html('');
                    }
                }
            );
            },
            del:function(){
                var ida = ut.getselv('sel');
                if(va.isnull(ida)){ut.m('请选择需要删除的信息.');return;}
                if(!window.confirm("确定删除么?执行后不可恢复."))return;
                $.get('../app/hotshop/delete_batch.shtm?t='+ut.r(), "ids="+ida, function(x){
                    var r = $.trim(x);
                    if(va.tint(r)){
                        ut.m('删除成功.已删除记录数为'+r);
                        Shop.list($curpage.val(),0);
                    }else{
                        ut.m('删除失败. '+r);
                    }
                });
            },
            updatePubState:function(){
                var ida = ut.getselv('sel');
                if(va.isnull(ida)){ut.m('请选择需要更新的信息.');return;}
                var st = $('#pubstate').val();
                if(va.isnull(st)){ut.m('请选择发布状态.');return;}
                var p = {'ids':ida,'pubstate':st};
                $.get('../app/hotshop/update_pubstate.shtm',$.param(p), function(x){
                    var r = $.trim(x);
                    if(va.tint(r)){
                        ut.m('更新成功.已更新记录数为'+r);
                        Shop.list($curpage.val(),0);
                    }else{
                        ut.m('更新失败. '+r);
                    }
                });
            },
            updateCmtState:function(){
                var ida = ut.getselv('sel');
                if(va.isnull(ida)){ut.m('请选择需要更新的信息.');return;}
                var st = $('#iscmt').val();
                if(va.isnull(st)){ut.m('请选择评论状态.');return;}
                var p = {'ids':ida,'iscmt':st};
                $.get('../app/hotshop/update_cmtstate.shtm',$.param(p), function(x){
                    var r = $.trim(x);
                    if(va.tint(r)){
                        ut.m('更新成功.已更新记录数为'+r);
                        Shop.list($curpage.val(),0);
                    }else{
                        ut.m('更新失败. '+r);
                    }
                });
            },
            updatePubTime:function(){
                var ida = ut.getselv('sel');
                if(va.isnull(ida)){ut.m('请选择需要更新的信息.');return;}
                var t  = $('#pubtime').val();
                if(!va.datetime(t)){ut.m('请选择发布时间！');return;}
                var p = {'ids':ida,'pubtime':ut.parseMs(t)};
                $.get('../app/hotshop/update_pubtime.shtm',$.param(p), function(x){
                    var r = $.trim(x);
                    if(va.tint(r)){
                        ut.m('更新成功.已更新记录数为'+r);
                        Shop.list($curpage.val(),0);
                    }else{
                        ut.m('更新失败. '+r);
                    }
                });
            },
            doUpdatetime:function(){
                var ida = ut.getselv('sel');
                if(va.isnull(ida)){ut.m('请选择需要更新的信息.');return;}
                var t  = $('#updatetime').val();
                if(!va.datetime(t)){t='';}
                var p = {'ids':ida,'updatetime':ut.parseMs(t)};
                $.get('../app/hotshop/update_time.shtm',$.param(p), function(x){
                    var r = $.trim(x);
                    if(va.tint(r)){
                        ut.m('更新成功.已更新记录数为'+r);
                        Shop.list($curpage.val(),0);
                    }else{
                        ut.m('更新失败. '+r);
                    }
                });
            },
            updateCatalog:function(){
                var ida = ut.getselv('sel');
                if(va.isnull(ida)){ut.m('请选择需要更新的信息.');return;}
                var cid = $('#cid').val();
                var ctp = $('#ctp').val();
                if(!va.isint(cid)){ut.m('请选择信息类别.');return;}
                var p = {'ids':ida, 'cid':cid, 'ctp':ctp};
                $.get('../app/hotshop/update_catelog.shtm',$.param(p), function(x){
                    var r = $.trim(x);
                    if(va.tint(r)){
                        ut.m('更新成功.已更新记录数为'+r);
                        Shop.list($curpage.val(),0);
                    }else{
                        ut.m('更新失败. '+r);
                    }
                });   
            },
            edit:function(id){
                win.open('shop_edit.html?id='+id);
            },
            view:function(id){
                window.open('../../hotshop/view.shtm?t='+ut.r()+'&id='+id,'_blank');
            }
        };

        function selectCatelogs(){
            var ct = $('#channeltype').val();
            if(!va.mint(ct)){
                TxBox.alert('请先选择板块.');
                return;
            }
            TxBox.winpop(250,350,'类目选择', 'catalogs_select_pop.html?channeltype='+ct);
        };

        function reloadCatData(cid,ctp){
            $('#cid').val(cid);
            $('#ctp').val(ctp);
            $('#ctp_name_path').text(cid+';'+ctp);
            TxBox.closeWinpop();
        };
            
        // 将过期的信息时间标注为高亮
        function highlightOverTime(t){
            var curTime = (new Date()).getTime();
            var timeStr = ut.parseDate(t,16);
            if(t>1000 && (Number(t)-curTime)<0){
                return '<span style="color:red">'+timeStr+'</span>';
            }
            return timeStr;
        };
            
        template.helper('parseDate',ut.parseDate);
        template.helper('highlightOverTime',highlightOverTime);
        template.helper('getResizeImgUrl',ImgKit.getResizeImgUrl);
        template.helper('getShopType',getShopType);
        template.helper('fmtNumber',ut.fmtNumber);
        template.helper('getPubState',getPubState);
        template.helper('getCmtState',getCmtState);
        
        jQuery(function(){
            $('#channeltype').val('1').attr('readonly','readonly');
            $('#channeltype').change(function(){
                $('#cid').val('');
                $('#ctp').val('');
                if($('#channeltype').val()!='1'){
                    $('#channeltype').val('1');
                }
            });
        });
    </script>
</body>
</html>
